package fy.hr.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import fy.config.FyConfig;
import fy.hr.bean.MemberBean;
import fy.util.DBUtil;


public class QueryMemberInfoFromHRDao {

	public static MemberBean queryMemberByCode(String code) throws Exception {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		MemberBean bean = null;
		try {
			conn = DBUtil.connect(FyConfig.getEHR_DB_CONFIG());

			pst = conn
					.prepareStatement("select p.psnname, p.psncode, b.basgroupdef14, b.mobile, b.basgroupdef1, b.basgroupdef4, d.deptname, j.jobname, c.unitshortname from bd_psndoc p left join bd_psnbasdoc b on p.pk_psnbasdoc = b.pk_psnbasdoc left join bd_deptdoc d on p.pk_deptdoc = d.pk_deptdoc left join om_job j on p.pk_om_job = j.pk_om_job left join bd_corp c on p.pk_corp = c.pk_corp where p.psnclscope in (0,5) and p.psncode = ?");
			// select p.psnname, p.psncode, b.addr, b.mobile, b.basgroupdef1,
			// b.basgroupdef4, d.deptname, j.jobname, c.unitshortname from
			// bd_psndoc p left join bd_psnbasdoc b on p.pk_psnbasdoc =
			// b.pk_psnbasdoc left join bd_deptdoc d on p.pk_deptdoc =
			// d.pk_deptdoc left join om_job j on p.pk_om_job = j.pk_om_job left
			// join bd_corp c on p.pk_corp = c.pk_corp where p.psnclscope = 0
			// and p.psncode = ?

			pst.setString(1, code);

			rs = pst.executeQuery();

			if (rs.next()) {
				bean = new MemberBean();
				bean.setName(rs.getString(1));
				bean.setCode(rs.getString(2));
//				bean.setAddress(rs.getString(3));
				bean.setTel(rs.getString(4));
//				bean.setIDCard(rs.getString(5));
				bean.setJoinDate(rs.getString(6));
				bean.setDept(rs.getString(7));
				bean.setPost(rs.getString(8));
				bean.setCorp(rs.getString(9));
			}

		} finally {
			DBUtil.close(rs, pst, conn);
		}
		return bean;
	}
}
